import React, { useState } from 'react'
import {
  Form,
  Input,
  Button,
  NavBar,
  Checkbox,
} from 'antd-mobile'
import styles from './login.module.scss'
import axios from '../../api/axios'
import {getLoginList} from '../../api/shoppService'
import { useNavigate } from 'react-router-dom'
const Index = () => {
  const [isAgreed, setIsAgreed] = useState(false)
   let navigate=useNavigate()
  const onFinish = async (values) => {
  // const res=await getLoginList(values.username,values.password)
  // console.log(res);
  const res=await axios.post('/tx/login',values)
  console.log(res);
  if(res.data.code===200){
    localStorage.setItem('token',res.data.data.accessToken)
    localStorage.setItem('userInfo',JSON.stringify(res.data.data.userInfo))
    navigate('/User')
  }
  }
  const handelgo=()=>{
    navigate('/register')
  }
  return (
    <div className={styles.logbox}>

      <NavBar back='取消' backIcon={false} onBack={()=>navigate('/')}>
      </NavBar>
      <div className={styles.logform}>
        <h2>登录春雨医生</h2>
        <Form
          layout='horizontal'
          className={styles.form}
          onFinish={onFinish}
          footer={
            <div>
              <div className={styles.agreement}>
                <Checkbox checked={isAgreed} onChange={setIsAgreed}>
                  我已阅读并同意
                  <a href="#" className={styles.link}>《春雨医生用户协议》</a>
                  <a href="#" className={styles.link}>《隐私政策》</a>未注册将自动完成账户注册
                </Checkbox>

              </div>
              <Button block type='submit' color="success" size='large' disabled={!isAgreed}>
                密码登录
              </Button>
            </div>

          }
        >
          <Form.Item
            // className={styles.form_item}
            name='username'
            label='姓名'
            rules={[{ required: true, message: '姓名不能为空' }]}
          >
            <Input placeholder='请输入姓名' />
          </Form.Item>
          <Form.Item
            name='password'
            label='密码'
            rules={[{ required: true, message: '姓名不能为空' }]}
          >
            <Input  placeholder='请输入密码' />
          </Form.Item>
        </Form>
        <p className={styles.registe} onClick={handelgo}>?没有密码，注册新账号</p>
      </div>

    </div>
  )
}

export default Index